package de.fuberlin.inf.alp4.uebg5;

import java.util.concurrent.Callable;
import java.util.concurrent.Future;
import java.util.concurrent.FutureTask;

/* The message request object serves both as the task we maintain
   internally and the future we return via the proxy. The class 
   is abstract, because concrete message request shall be
   derived, which then provide the guard and the code to execute. */
public abstract class MessageRequest<V> extends FutureTask<V> implements Future<V> {
    /* In this implementation every message request holds a reference to
       the servant object. The reference may be used for accessing the
       attributes of the servant object when testing guards. */
    protected final Servant servant;
    protected int priority;

    protected MessageRequest(Servant servant, Callable<V> callable, int priority) {
        super(callable);
        this.servant = servant;
        this.priority = priority;
    }

    /** A condition under which the request shall be executed. The
        default is <code>true</code>, i.e. the message shall be always
        executed. */
    public abstract boolean guard();
    
    /**
     * Information about the MessageRequest
     * @return M1 || M2
     */
    public abstract String getRequestType();
}
